home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.direct.ca!usenet
- From: qjackson@direct.ca
- Newsgroups: comp.lang.c++
- Subject: [Q] Pointers to Arrays (or not)
- Date: Wed, 06 Mar 1996 15:40:23 GMT
- Organization: Parsepolis Software
- Message-ID: <4hkbg9$cja@aphex.direct.ca>
- Reply-To: qjackson@direct.ca
- NNTP-Posting-Host: 204.174.249.114
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hello:
-
- I've come across something that I'm wondering about.
-
- I have a class, Foo, with a member that is a pointer to Bar, where Bar
- can be either a single object of Bar, or an array of Bar, depending on
- other semantics:
-
-
- class Foo
- {
-
- Bar* pBar;
- int barTab; // how many Bar's are pointed to be pBar
-
- ~Foo (void);
-
- };
-
- I would have thought that I could kill pBar this way:
-
- delete [] pBar;
-
- but that crashes if pBar was instantiated thus:
-
- pBar = new Bar;
-
- So, my destructor has this:
-
-
- Foo::~Foo (void)
- {
-
- switch (barTab)
- {
- case 0:
- break;
-
- case 1:
- delete pBar;
- break;
-
- default:
- delete [] pBar;
- break;
-
- }
-
- }
-
- Without this, under VC++ 1.52, the system is prone to crash.
-
- What am I missing?
-
-
- Thanks in advance,
-
-
-
-
-
-
-
-
-
- --
- |
- Parsepolis Software | Quinn Tyler Jackson
- "ParseCity" | (aka 'Jamshid')
- >--------------------------| qjackson@direct.ca
- |---------------------->
-
-